package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/09/08 09:33
 **/
public class Day6_1_Num667_ConstructArray {
    class Solution {
        public int[] constructArray(int n, int k) {
            int[] res = new int[n];
            int odd = 1, even = k+1;
            //下标段[0, k]中，偶数下标填充[1,2,3..]
            for(int i = 0; i <= k; i+=2){
                res[i] = odd++;
            }
            //下标段[0, k]中，奇数下标填充[k + 1, k, k - 1...]
            for(int i = 1; i <= k; i+=2){
                res[i] = even--;
            }
            //下标段[k + 1, n - 1]都是顺序填充
            for(int i = k+1; i < n; ++i){
                res[i] = i+1;
            }
            return res;
        }
    }
}